package com.gcmm.handler;


import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.ui.Model;

/**
 * 全局异常处理器，处理项目中抛出的业务异常
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    /**
     * 捕获业务异常
     * @param ex
     * @return
     */
    @ExceptionHandler
    public String exceptionHandler(Exception ex,Model model){
        log.error("error massage 1 ：{}", ex.getMessage());
        ex.printStackTrace();
        log.info("error massage 2 : {}",ex.getStackTrace().toString());

        model.addAttribute("errorMessage",ex.getMessage());

        return "error";
    }



}
